﻿using BaseUi.ViewModels;
using BaseUi.Views.MainWindows;
using HandyControl.Controls;
using LiveCharts.Dtos;
using Ping9719.WpfEx;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace BaseUi.Views.PlcView
{
    public class StudentData : INotifyPropertyChanged
    {
        public CommonViewModel CommonViewModel { get; set; }
        /// <summary>
        /// Y轴到安全位
        /// </summary>
        private SolidColorBrush ytosafeColor =MainWindow4.ytosafe;
        /// <summary>
        /// 入料皮带正转
        /// </summary>
        private SolidColorBrush FeedcoroColor = new SolidColorBrush();
        /// <summary>
        /// 搅拌机倾斜转动
        /// </summary>
        private SolidColorBrush BlenderslanColor = new SolidColorBrush();
        /// <summary>
        /// 搅拌机水平转动
        /// </summary>
        private SolidColorBrush BlenderlevelColor = new SolidColorBrush();

        public SolidColorBrush ytosafe
        {
            get { return MainWindow4.ytosafe; }
            set
            {
                ytosafeColor = value;

                OnPropertyChanged("ytosafe");
            }
        }
        public SolidColorBrush Feedcoro
        {
            get { return FeedcoroColor; }
            set
            {
                FeedcoroColor = value;

                OnPropertyChanged("Feedcoro");
            }
        }
        public SolidColorBrush Blenderslan
        {
            get { return BlenderslanColor; }
            set
            {
                BlenderslanColor = value;

                OnPropertyChanged("Blenderslan");
            }
        }
        public SolidColorBrush Blenderlevel
        {
            get { return BlenderlevelColor; }
            set
            {
                BlenderlevelColor = value;

                OnPropertyChanged("Blenderlevel");
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;
        protected void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }
    /// <summary>
    /// WarmingToColdPositionView.xaml 的交互逻辑
    /// </summary>
    public partial class WarmingToColdPositionView : UserControlBase
    {
        private StudentData viewModel = new StudentData();
        public SolidColorBrush RedColor = new SolidColorBrush(Color.FromRgb(255, 69, 0));
        public SolidColorBrush GreenColor = new SolidColorBrush(Color.FromRgb(173, 255, 47));
        public SolidColorBrush BoroColor = new SolidColorBrush(Color.FromRgb(220, 220, 220)); 
        public SolidColorBrush LemonChiffonColor = new SolidColorBrush(Color.FromRgb(255, 250, 205));
        public WarmingToColdPositionView()
        {
            InitializeComponent();
            DataContext = viewModel;
            viewModel.CommonViewModel = MainWindow4.viewModel.CommonViewModel;
        }

        private void loadFirst(object sender, EventArgs e)
        {
            if (this.IsInDesignMode)
                return;
            getwar();

        }

        private void getwar()
        {
            var ioi = LocalStatic.Plc.Read<Int16>("0");
            if (ioi.IsSucceed==false)
            {
                warTcopBox1g1.Text ="未接收";
            }
            else
            {
                warTcopBox1g1.Text = ioi.Value.ToString();
            }
            ioi = LocalStatic.Plc.Read<Int16>("3");
            if (ioi.IsSucceed == false)
            {
                warTcopBox1g2.Text = "未接收";
            }
            else
            {
                warTcopBox1g2.Text = ioi.Value.ToString();
            }
            ioi = LocalStatic.Plc.Read<Int16>("1");
            if (ioi.IsSucceed == false)
            {
                warTcopBox1g3.Text = "未接收";
            }
            else
            {
                warTcopBox1g3.Text = ioi.Value.ToString();
            }
            ioi = LocalStatic.Plc.Read<Int16>("2");
            if (ioi.IsSucceed == false)
            {
                warTcopBox1g4.Text = "未接收";
            }
            else
            {
                warTcopBox1g4.Text = ioi.Value.ToString();
            }
            //warTcopBox1g1.Text = LocalStatic.Plc.Read<Int16>("0").Value.ToString();
            //warTcopBox1g2.Text = LocalStatic.Plc.Read<Int16>("3").Value.ToString();
            //warTcopBox1g3.Text = LocalStatic.Plc.Read<Int16>("1").Value.ToString();
            //warTcopBox1g4.Text = LocalStatic.Plc.Read<Int16>("2").Value.ToString();
        }

        private void warTcopButton_Click1g1z1(object sender, RoutedEventArgs e)
        {
            try
            {
                var ioi = LocalStatic.Plc.Write<bool>("111", true);
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void warTcopButton_Click1g3z1(object sender, RoutedEventArgs e)
        {
            getwar();
        }

        private void warTcopButton_Click1g3z2(object sender, RoutedEventArgs e)
        {
            try
            {
                short ser = Convert.ToInt16(warTcopBox1g1.Text);
                var ioi = LocalStatic.Plc.Write<Int16>("0", ser);
                ser = Convert.ToInt16(warTcopBox1g2.Text);
                var ioi2 = LocalStatic.Plc.Write<Int16>("3", ser);
                ser = Convert.ToInt16(warTcopBox1g3.Text);
                var ioi3 = LocalStatic.Plc.Write<Int16>("1", ser);
                ser = Convert.ToInt16(warTcopBox1g4.Text);
                var ioi4 = LocalStatic.Plc.Write<Int16>("2", ser);
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("冷库层上传失败");
                }
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("冷库列上传失败");
                }
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("回温层上传失败");
                }
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("回温列上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void warTcopButton_Click1g4z1(object sender, RoutedEventArgs e)
        {
            try
            {
                var ioi = LocalStatic.Plc.Write<bool>("55", true);
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void warTcopButton_Click1g4z2(object sender, RoutedEventArgs e)
        {
            try
            {
                var ioi = LocalStatic.Plc.Write<bool>("74", true);
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void warTcopButton_Click1g5z1(object sender, RoutedEventArgs e)
        {
            try
            {
                var ioi = LocalStatic.Plc.Write<bool>("90", true);
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void warTcopButton_Click1g5z2(object sender, RoutedEventArgs e)
        {
            try
            {
                var ioi = LocalStatic.Plc.Write<bool>("135", true);
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void warTcopButton_Click1g6z1(object sender, RoutedEventArgs e)
        {
            try
            {
                var ioi = LocalStatic.Plc.Write<bool>("39", true);
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void warTcopButton_Click2g1z1(object sender, RoutedEventArgs e)
        {
            try
            {
                var ioi = LocalStatic.Plc.Write<bool>("109", true);
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void warTcopButton_Click2g2z1(object sender, RoutedEventArgs e)
        {
            try
            {
                var ioi = LocalStatic.Plc.Write<bool>("56", true);
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void warTcopButton_Click2g3z1(object sender, RoutedEventArgs e)
        {
            try
            {
                var ioi = LocalStatic.Plc.Write<bool>("111", true);
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void warTcopButton_Click2g4z1(object sender, RoutedEventArgs e)
        {
            try
            {
                var ioi = LocalStatic.Plc.Write<bool>("53", true);
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void warTcopButton_Click2g4z2(object sender, RoutedEventArgs e)
        {
            try
            {
                var ioi = LocalStatic.Plc.Write<bool>("73", true);
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void warTcopButton_Click2g5z1(object sender, RoutedEventArgs e)
        {
            try
            {
                var ioi = LocalStatic.Plc.Write<bool>("38", true);
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void warTcopButton_Click3g1z1(object sender, RoutedEventArgs e)
        {
            try
            {
                var ioi = LocalStatic.Plc.Write<bool>("54", true);
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void warTcopButton_Click3g2z1(object sender, RoutedEventArgs e)
        {
            try
            {
                var ioi = LocalStatic.Plc.Write<bool>("108", true);
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void warTcopButton_Click3g3z1(object sender, RoutedEventArgs e)
        {
            try
            {
                var ioi = LocalStatic.Plc.Write<bool>("111", true);
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }

        private void warTcopButton_Click3g4z1(object sender, RoutedEventArgs e)
        {
            try
            {
                var ioi = LocalStatic.Plc.Write<bool>("136", true);
                if (ioi.IsSucceed == false)
                {
                    Growl.Error("上传失败");
                }
            }
            catch (Exception ee)
            {
                Growl.Error(ee.ToString());
            }
        }
    }
}
